/**
 * Copyright (c) 2018 软唐 All rights reserved.
 *
 * https://www.softtown.cn
 *
 * 版权所有，侵权必究！
 */

package com.softtown.modules.dapai.controller;

import com.github.pagehelper.PageInfo;
import com.softtown.common.utils.Result;
import com.softtown.modules.dapai.dto.*;
import com.softtown.modules.dapai.entity.CompCustomerEntity;
import com.softtown.modules.dapai.entity.CompCustomerPotentialEntity;
import com.softtown.modules.dapai.entity.CompCustomerResourceEntity;
import com.softtown.modules.dapai.service.CompCustomerPotentialService;
import com.softtown.modules.dapai.service.CompCustomerResourceService;
import com.softtown.modules.dapai.service.CompCustomerService;
import com.softtown.modules.dapai.vo.CompCustomerPotentialByContactVO;
import com.softtown.modules.dapai.vo.CompCustomerPotentialVO;
import com.softtown.modules.dapai.vo.CompCustomerVO;
import com.softtown.modules.dapai.vo.CustomerContactsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 潜在客户管理
 *
 * @author Ding Ya Yong
 */
@RestController
@RequestMapping("potential")
@Api(tags="潜在客户管理")
public class CompCustomerPotentialController {

    @Resource
    private CompCustomerPotentialService compCustomerPotentialService;

    @Resource
    private CompCustomerResourceService compCustomerResourceService;

    @PostMapping("getPotentialPageList")
    @ApiOperation("获取潜在客户管理分页")
    public Result getPotentialPageList(@RequestBody CompCustomerPotentialDTO compCustomerPotentialDTO) {
        PageInfo<CompCustomerPotentialEntity> customerEntityPageInfo = compCustomerPotentialService.getPotentialPageList(compCustomerPotentialDTO);
        return new Result<PageInfo<CompCustomerPotentialEntity>>().ok(customerEntityPageInfo);
    }



    @PostMapping("getPotentialById")
    @ApiOperation("获取潜在客户管理详情")
    public Result<CompCustomerPotentialVO> getPotentialById(@RequestBody  CompCustomerPotentialDTO compCustomerPotentialDTO) {
        CompCustomerPotentialVO compCustomerPotentialVO = compCustomerPotentialService.getPotentialById(compCustomerPotentialDTO.getCompId(),compCustomerPotentialDTO.getId());
        return new Result<CompCustomerPotentialVO>().ok(compCustomerPotentialVO);
    }


    @PostMapping("addPotential")
    @ApiOperation("添加潜在客户管理")
    public Result addPotential(@RequestBody CustomerPotentialAddOrUpdateDTO customerPotentialAddOrUpdateDTO) {
        Result result = new Result<>();
        compCustomerPotentialService.addPotential(customerPotentialAddOrUpdateDTO);
        return result;
    }


    @PostMapping("updatePotential")
    @ApiOperation("编辑潜在客户管理")
    public Result updatePotential(@RequestBody CustomerPotentialAddOrUpdateDTO customerPotentialAddOrUpdateDTO) {
        Result result = new Result<>();
        compCustomerPotentialService.updatePotential(customerPotentialAddOrUpdateDTO);
        return result;
    }

    @PostMapping("deletePotential")
    @ApiOperation("删除潜在客户管理")
    public Result deletePotential(@RequestBody CompCustomerPotentialDTO compCustomerPotentialDTO) {
        Result result = new Result<>();
        compCustomerPotentialService.deletePotential(compCustomerPotentialDTO.getCompId(),compCustomerPotentialDTO.getId());
        return result;
    }

    @PostMapping("transPotential")
    @ApiOperation("转为正式客户")
    public Result transPotential(@RequestBody CompCustomerPotentialDTO compCustomerPotentialDTO) {
        Result result = new Result<>();
        compCustomerPotentialService.transPotential(compCustomerPotentialDTO.getCompId(),compCustomerPotentialDTO.getId());
        return result;
    }

    @PostMapping("getPotentialContactList")
    @ApiOperation("获取潜在客户名单分页")
    public Result getPotentialContactList(@RequestBody CompCustomerPotentialByContactDTO compCustomerPotentialByContactDTO) {
        PageInfo<CompCustomerPotentialByContactVO> customerEntityPageInfo =
                compCustomerPotentialService.getPotentialContactList(compCustomerPotentialByContactDTO);
        return new Result<PageInfo<CompCustomerPotentialByContactVO>>().ok(customerEntityPageInfo);
    }


    @PostMapping("getResourcePageListApp")
    @ApiOperation("获取app客户资源分页")
    public Result getResourcePageListApp(@RequestBody CustomerResourceDTO customerResourceDTO) {
        PageInfo<CompCustomerResourceEntity> compCustomerResourceEntityPageInfo = compCustomerResourceService.getResourcePageListApp(customerResourceDTO);
        return new Result<PageInfo<CompCustomerResourceEntity>>().ok(compCustomerResourceEntityPageInfo);
    }



    @PostMapping("getResourceByIdApp")
    @ApiOperation("获取app客户资源详情")
    public Result<CompCustomerResourceEntity> getResourceByIdApp(@RequestBody CustomerResourceDTO customerResourceDTO) {
        CompCustomerResourceEntity compCustomerResourceEntity = compCustomerResourceService.getResourceByIdApp(customerResourceDTO.getCompId(),customerResourceDTO.getId());
        return new Result<CompCustomerResourceEntity>().ok(compCustomerResourceEntity);
    }


    @PostMapping("addResourceApp")
    @ApiOperation("添加app客户资源")
    public Result addResourceApp(@RequestBody CustomerAddResourceDTO customerAddResourceDTO) {
        Result result = new Result<>();
        compCustomerResourceService.addResourceApp(customerAddResourceDTO);
        return result;
    }


    @PostMapping("updateResourceApp")
    @ApiOperation("编辑app客户资源")
    public Result updateResourceApp(@RequestBody CustomerAddResourceDTO customerAddResourceDTO) {
        Result result = new Result<>();
        compCustomerResourceService.updateResourceApp(customerAddResourceDTO);
        return result;
    }

    @PostMapping("deleteResourceApp")
    @ApiOperation("删除app客户资源")
    public Result deleteResourceApp(@RequestBody CustomerResourceDTO customerResourceDTO) {
        Result result = new Result<>();
        compCustomerResourceService.deleteResourceApp(customerResourceDTO.getCompId(),customerResourceDTO.getId());
        return result;
    }


    @PostMapping("getResourceListApp")
    @ApiOperation("获取app客户资源下拉")
    public Result<List<CompCustomerResourceEntity>> getResourceListApp(@RequestBody CustomerResourceDTO customerResourceDTO) {
        List<CompCustomerResourceEntity> compCustomerResourceEntities = compCustomerResourceService.getResourceListApp(customerResourceDTO);
        return new Result<List<CompCustomerResourceEntity>>().ok(compCustomerResourceEntities);
    }


}